# coding:utf-8
"""
朱瑞要求筛选热门ABtest数据
"""
from qa.interface.app.parameters import ia_token, ia_http
import hashlib

__author__ = 'jiaoshupeng'
import sqlite3

sqldb = sqlite3.connect("db.sqlite3", check_same_thread=False)
cursor = sqldb.cursor()


def getdata(username, password, url):
    myhttp = ia_http.py_http()
    passwd = hashlib.sha1(password).hexdigest()
    # print ia_token.addHeader(1, username, passwd, "https://argo.blued.cn", 1)
    auth = ia_token.addHeader(1, username, passwd, "https://argo.blued.cn", 1)[2]
    data = myhttp.http_read(url, auth, 5, '')
    return data


def select_lid(team):
    list = []
    cursor.execute("SELECT lid FROM db_onairlist WHERE team = '%s'" % team)
    rows = cursor.fetchall()
    for lid in rows:
        list.append(lid[0])
    return list


def insert_lid(lid, uid, team):
    cursor.execute("insert INTO db_onairlist(lid, uid, team) VALUES (%s, %s, '%s')" % (uid, lid, team))
    sqldb.commit()


def del_lid():
    cursor.execute("DELETE FROM db_onairlist")
    sqldb.commit()

# insert_lid('123', '321', 'a')

# print select_lid()
# insert_lid('666', '999')
# url = "https://argo.blued.cn/live/onairlist?page=1"
# getdata('2574006368@qq.com', '123456', url)
